<template>
  <div class="co_party_create co_party">
    <Row style="width: 600px;">
      <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <FormItem label="合作方名称" prop="partnerName">
          <Input
            type="text"
            v-model="formValidate.partnerName"
            v-filterinput="{ reg: regExp.special }"
            style="width: 280px;"
            :maxlength="50"
          ></Input>
        </FormItem>
        <FormItem class="form-btn" style="margin-top: 5px;">
          <Button
            type="primary"
            class="pa-submit-btn"
            style="margin-right: 15px;"
            @click="submit"
          >提交</Button>
          <Button @click="back" class="pa-submit-btn">返回</Button>
        </FormItem>
      </Form>
    </Row>
    <!-- <div class="search-box">
      <Row type="flex">
        <Col class="search-item">
        <span class="search-label">合作方名称:</span>
        <Input v-model="searchObj.Name"
               disabled
               :maxlength="30"
               placeholder="请输入">
        </Input>
        </Col>
      </Row>
      <Row>
        </Col>
        <Col class="search-item">
        <Button class="search-btn"
                type="primary"
                @click="doSearch">返回</Button>
        </Col>
    </Row>-->
    <!-- </div> -->
  </div>
</template>
<script>
import { createPartneList } from '@/api/system/fishing.js'
import regExp from '@/libs/regExp'
import { mapState } from 'vuex'
import { routeEqual } from '@/libs/util'
import './main.less'
export default {
  name: 'cooperation_party_create',
  data () {
    return {
      formValidate: {
        partnerName: ''
      },
      isTrue: true,
      regExp: regExp,
      ruleValidate: {
        partnerName: [{ required: true, message: '合作方名称不能为空', trigger: 'blur' }]
      }
    }
  },
  computed: {
    ...mapState({
      merchantId: state => state.user.merchantId,
      userId: state => state.user.userId,
      userName: state => state.user.userName
    })
  },
  methods: {
    back () {
      this.closeModal()
    },
    closeModal () {
      this.$store.commit('closeTag', this.$route)
      this.$store.commit('setTagNavList', this.$store.state.app.tagNavList.filter(item => !routeEqual(this.$route, item)))
      this.$nextTick(() => {
        this.$router.push({
          name: 'cooperation_party_list'
        })
      })
    },
    submit () {
      this.$refs.formValidate.validate((val) => {
        if (val) {
          if (this.isTrue) {
            this.isTrue = false
            createPartneList({
              ...this.formValidate,
              merchantId: this.merchantId,
              creator: this.userId,
              creatorName: this.userName
            }).then(res => {
              setTimeout(() => {
                this.isTrue = true
              }, 2000)
              if (res.data.status === 200) {
                this.$Message.success('新增成功')
                this.closeModal()
              } else {
                this.$Message.error(`${res.data.error}`)
              }
            })
          }
        }
      })
    }
  }
}
</script>
